# -*-coding:utf-8-*-
"""
@project: python-project
@Time: 2024-07-15 13:45
@Author: Loneliness_Burial
@File: numpy求迹.py
@Motto: 深情不改必坠死海
@software: pycharm
@version: python 3.7
"""

import numpy as np

arr = np.random.randint(1, 10, (3, 3))
print("创建一个二维数组:\n", arr)
arr_res = arr.trace()
print("这个数组的迹为:\n", arr_res)
print("-" * 20)
arr2 = np.random.randint(1, 10, (2, 3, 4))
print("创建一个二维数组:\n", arr2)
arr_res = arr2.trace()
print("这个数组的迹为:\n", arr_res)
print("-" * 20)
arr_res = arr2.trace(axis1=1, axis2=2)
print("这个数组的迹为:\n", arr_res)
